

	project , uses("constituency_elections.dta")


	*margins
	use "constituency_elections.dta", clear //open data
	replace spending_limit_predicted_adj=10000*spending_limit_predicted_adj
	foreach v in spending_total_adj candidates effective_candidates effective_spenders inc_vote_pct inc_spending_pct  { //
		
		reghdfe `v' spending_limit_predicted_adj countyXelectors, absorb(const_id date i.date#c.electors)
		
		marginscontplot spending_limit_predicted_adj, ci at1(0(5000)175000) ///
		plotopts( xtitle("Spending Limit" ) ytitle("`: var la `v''" ) xlabel(0 (25000) 175000, angle(30)) saving( ./figures/marginsplot_`v'.gph, replace) )  
		
		
	}

	graph combine "./figures/marginsplot_spending_total_adj.gph" "./figures/marginsplot_candidates.gph" "./figures/marginsplot_effective_candidates.gph" "./figures/marginsplot_effective_spenders.gph"  "./figures/marginsplot_inc_spending_pct.gph" "./figures/marginsplot_inc_vote_pct.gph" ,  cols(2) xsize(15) ysize(12) 
	graph export ./figures/marginsplot.pdf, replace				
	
	
	project , creates("figures/marginsplot.pdf")	
	
	
	
	use "constituency_elections.dta", clear //open data
	foreach v in spending_total_adj candidates effective_candidates effective_spenders inc_vote_pct inc_spending_pct  {
		reghdfe `v'   countyXelectors c.spending_limit_predicted_adj##c.margin_prev, absorb( const_id election election#c.electors) cluster(const_id)
		margins ,  dydx(spending_limit_predicted_adj) at(margin_prev= (0 (10) 100) ) 
		marginsplot , recastci(rarea)  plotopts( xtitle("Margin of Victory, t-1" ) ytitle("Estimated Effect of" "Spending Limit (£10,000)" "on `: var la `v''")  ) title(" ") saving( ./figures/marginsplot_interaction_`v'.gph, replace)
	}
	
	
	graph combine "./figures/marginsplot_interaction_spending_total_adj.gph" "./figures/marginsplot_interaction_candidates.gph" "./figures/marginsplot_interaction_effective_candidates.gph" "./figures/marginsplot_interaction_effective_spenders.gph"  "./figures/marginsplot_interaction_inc_spending_pct.gph" "./figures/marginsplot_interaction_inc_vote_pct.gph" ,  cols(2) xsize(15) ysize(12) 
	graph export ./figures/marginsplot_interaction.pdf, replace				

	project , creates("figures/marginsplot_interaction.pdf")	
